import { reqCategoryList, reqGetBannerList, reqFloorList } from "@/api"
const state = {
  categoryList: [],
  bannerList: [],
  floorList: []
}

//mutations 修改state的唯一手段  state.categoryList是上方state里的空数组，后面的赋值是从actions里收到的参数result.data
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  GETBANNNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLIST(state, floorList) {
    state.floorList = floorList
  },

}

//actions 可以书写的业务
const actions = {
  async categoryList({ commit }) {
    let result = await reqCategoryList()
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data)
    }
  },
  async getBannerList({ commit }) {
    let result = await reqGetBannerList()
    if (result.code == 200) {
      commit('GETBANNNERLIST', result.data)
    }
  },
  async getFloorList({ commit }) {
    let result = await reqFloorList()
    if (result.code == 200) {
      commit('GETFLOORLIST', result.data)
    }
  },
}


//理解为计算属性用于简化仓库数 ，让组件读取数据更快
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters
}